package com.itboye.ihomebank.activity.myzhujia.qianbao;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

import java.util.Observable;
import java.util.Observer;
/**
 * 忘记原支付密码(1,输入手机号)
 *
 */
public class ActivityWangJiPass extends BaseOtherActivity implements Observer{
	View v_statusbar;
	ImageView close_icon;//返回图片
	TextView add_shap_title_tv;//标题
	EditText pass_one_tel;//手机号
	TextView pass_one_ok;//下一步
	
	private UserPresenter userPresenter;
	
	String phone;
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.pass_one_ok:
			
			if(phone.equals(pass_one_tel.getText().toString())){
				userPresenter = new UserPresenter(this);
				userPresenter.send(pass_one_tel.getText().toString().trim(), "7");
			}else{
				ByAlert.alert("请输入正确的手机号");
			}
			
			break;

		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_wangji_pass;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {

		setStatusBarHeight(v_statusbar);
		add_shap_title_tv.setText("找回支付密码");
		
		phone=(String)SPUtils.get(this, null, SPContants.MOBILE, "");

	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity=handlerError(data);
		if(entity!=null){
			if(!entity.getCode().equals(0)){
				if(entity.getEventType()==UserPresenter.send_success){
					String bean=(String) entity.getData();
					if(bean!=null){
						ByAlert.alert("验证码发送成功");
						Intent intent=new Intent(ActivityWangJiPass.this,ActivityWangJiPassTwo.class);
						intent.putExtra("phone", pass_one_tel.getText().toString());
						intent.putExtra("yzm", bean.trim());
						Log.d("====wangji",bean);
						startActivity(intent);
						finish();
					}else{
						ByAlert.alert("失败");
					}
				}if(entity.getEventType() == UserPresenter.send_fail){
					ByAlert.alert("验证码发送失败");
				}
			}
		}
		
	}

}
